﻿using System;
using System.Collections.Generic;
using UnityEngine;

namespace JQMergeFramework
{

    public class PoolName
    {
        //烟雾特效
        public const string SmokeCircle = "SmokeCirclePool";
        
        //盖房子特效
        public const string BuildTheHouse = "BuildTheHousePool";

        //房子等级提示文本
        public const string CityLvText = "CityLvTextPool";

        //塔吊平台
        public const string TrackTemplate = "TrackTemplatePool";

        //锤子模型预制体
        public const string Hammer = "HammerPool";
        
        //导弹模型
        public const string GuidedMissile = "GuidedMissilePool";
        
        //导弹爆炸特效
        public const string CityBomb = "CityBombPool";
        
        //等级提示UI
        public const string PreviewLvTips = "PreviewLvTipsPool";

        //合成分数增加拖尾
        public const string MergeTrailing = "MergeTrailingPool";
        
        //金币模型
        public const string Coin = "CoinPool";
    }

    public class EffectPool: MonoBehaviour
    {
        public static EffectPool I;
        
        public Dictionary<string, BhvEasyPool> dictPool = new Dictionary<string, BhvEasyPool>();
        private void Awake()
        {
            I = this;
            
            BhvEasyPool[] easyPoolAry = this.transform.GetComponentsInChildren<BhvEasyPool>();

            for (int i = 0; i < easyPoolAry.Length; i++)
            {
                dictPool.Add(easyPoolAry[i].gameObject.name,easyPoolAry[i]);
            }
        }


        public GameObject GetPoolObject(string name)
        {
            if (dictPool.ContainsKey(name))
            {
                return dictPool[name].Get();
            }

            return null;
        }

        
        public void PutPoolObject(string name,GameObject poolObject)
        {
            if (dictPool.ContainsKey(name))
            {
                dictPool[name].Put(poolObject);
            }
        }
        
        public void PutPoolObject(string name,GameObject poolObject,float time)
        {
            if (dictPool.ContainsKey(name))
            {
                dictPool[name].Put(poolObject,time);
            }
        }
        
    }
}